// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    date:'',
    time1: '19:00',//默认起始时间  
    time2: '20:00',//默认结束时间 
    display1:'none',
    result:''
  },

  // 时间段选择  
  bindDateChange(e) {
    let that = this;
    console.log(e.detail.value)
    that.setData({
      time1: e.detail.value,
    })
  },
  bindDateChange2(e) {
    let that = this;
    that.setData({
      time2: e.detail.value,
    })

  },
  //日期改变
  bindDateChange3: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value),
    this.setData({
      date: e.detail.value
    })
  },
  gotoContent:function(e){
    // console.log('sub保存的数据是',  this.data.time1,this.data.time2,this.data.date)
    this.setData({
      display1:'block'
    })
    wx.request({
      url: 'https://yali.geekwhite.cn:3000/select',
      header:{'Access-Control-Allow-Origin':'*'},
      header:{'Access-Control-Allow-Methods':'GET,POST'},
      data:{
        time1:this.data.time1,
        time2:this.data.time2, 
        date:this.data.date
      },  
      method:'post',
      success:function(res){
        // this.setData({
        //   result:res.data,
        //   display1:'block'
        // })
        console.log(res.data);
        wx.setStorageSync('result', res.data)
      }
    }) 
    this.setData({
      result:wx.getStorageSync('result')
    })
},
  onLoad() {
    let dd=new Date();
    let y=dd.getFullYear();
    let m=dd.getMonth()+1;
    let d=dd.getDate();
    let now=y+'-'+m+'-'+d
    this.setData({
      date:now
    })
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      }),
      wx.setNavigationBarTitle({
        title: '自选时段',
      })
    } 
  },
  getUserInfo(e) {
    // 不推荐使用getUserInfo获取用户信息，预计自2021年4月13日起，getUserInfo将不再弹出弹窗，并直接返回匿名的用户个人信息
    console.log(e)
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  //申请占用按钮
  // confirmtake(){
  //   wx.navigateTo({
  //     url: '/pages/apply/apply?date='+this.data.date+'&time1'+this.data.time1+'&time2'+this.data.time2,
  //     // url: '/pages/apply/apply',
  //   })
  //   // console.log(this.data.date,this.data.time1,this.data.time2)
  // },
  //表单提交事件
  formSubmit() {  
    console.log('form发生了submit事件，携带数据为：', data.inputname)
  },
  //表单重置事件
  formReset(e) {
    console.log('form发生了reset事件，携带数据为：', e.detail.value)
    this.setData({
      chosen: ''
    })
  }
})
